#include "CSimplerConsequent.h"
#include "CLSystem.h"
#include "CLSysErrorMsg.h"

CSimplerConsequent::CSimplerConsequent(CLSystem const* ptr_ls)
    : ptr_lsystem(ptr_ls)
{
}

void CSimplerConsequent::Get(std::string& str_conseq) const
{
    str_conseq = consequent;
}

void CSimplerConsequent::GetFormatted(std::string& str_conseq) const
{
    str_conseq = consequent;
}

void CSimplerConsequent::Set(std::string const& str_conseq)
{
    if(!str_conseq.size())
        if(!ptr_lsystem->AllowEmptyConsequent())
            throw CLSysErrorMsg(CLSysErrorMsg::LS_EMPTY_CONSEQUENT_NOT_ALLOWED);

    unsigned int i(0);
    while(i < str_conseq.size())
    {
        const char c(str_conseq[i++]);
        if(!ptr_lsystem->IsValidSymbol(c) && !ptr_lsystem->IsValidControlSymbol(c))
            throw CLSysErrorMsg(CLSysErrorMsg::LS_CONSEQUENT_UNEXPECTED_CHAR,str_conseq,c);
    }

    consequent = str_conseq;
}

void CSimplerConsequent::Check(void) const
{
    if(!consequent.size())
        if(!ptr_lsystem->AllowEmptyConsequent())
            throw CLSysErrorMsg(CLSysErrorMsg::LS_EMPTY_CONSEQUENT_NOT_ALLOWED);

    unsigned int i(0);
    while(i < consequent.size())
    {
        const char c(consequent[i++]);
        if(!ptr_lsystem->IsValidSymbol(c) && !ptr_lsystem->IsValidControlSymbol(c))
            throw CLSysErrorMsg(CLSysErrorMsg::LS_CONSEQUENT_UNEXPECTED_CHAR,consequent,c);
    }
}
